﻿using CommHelper;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace Test.Update
{
    internal class UpdateWordMean
    {

        public static async Task UpdateMean()
        {

            await Task.Run(() =>
            {
                DataManager dm = new DataManager();
                DataTable dt = dm.SqlCmd("SELECT CBW.ID,BaseWordID,Mean,Word FROM Cus_BookWord CBW inner join Base_Words BW on BW.ID = CBW.BaseWordID where Word not in ('.',',')").table;

                int count = 0;
                foreach (DataRow dr in dt.Rows)
                {
                    string ID = dr["ID"].ToString();
                    string BaseWordID = dr["BaseWordID"].ToString();
                    string Mean = dr["Mean"].ToString();
                    string Word = dr["Word"].ToString();

                    // 判断Mean是否是不包含汉字的字符串，使用正则表达式
                    string pattern = @"^[a-zA-Z.?!\(\)（）？！'\-, ]+$";
                    bool isMatch = Regex.IsMatch(Mean, pattern);
                    if (isMatch)
                    {
                        count++;

                        // 从SDE库中获取Mean
                        //dm.Procedure("TEST_UpdateWordMean", "[{\"ID\":\"" + ID + "\"}]");

                        // 从AI获取Mean

                        Console.WriteLine("ID: " + ID + " Word: " + Word + " Mean: " + Mean);
                    }
                }
                Console.WriteLine("匹配到的行数：" + count);
                Console.ReadKey();
            });
        }
    }
}
